﻿/** \file
* \$Rev: 3 $
* 
* \$Date: 2010-06-20 21:00:41 +0000 (Sun, 20 Jun 2010) $
*
* \$URL: http://fofbrainz.googlecode.com/svn/trunk/MusicBrainz/XmlObjects.cs $
*/

using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace FofBrainz.MusicBrainz
{
	/// <summary>The returned result of a MusicBrainz track search.</summary>
	[XmlRoot(Namespace = "http://musicbrainz.org/ns/mmd-1.0#")]
	public class metadata
	{
		/// <summary>The container element for the list of tracks.</summary>
		[XmlElement("track-list")]
		public tracklist TrackList { get; set; }

		/// <summary>Get a list of tracks sorted by rank.</summary>
		/// <param name="artistname">The ideal artist name.</param>
		/// <param name="trackname">The ideal track name.</param>
		/// <returns>The sorted track list.</returns>
		public List<RankedTrack> GetRankedTracks(string artistname, string trackname)
		{
			List<RankedTrack> ranked = new List<RankedTrack>();
			foreach (track track in TrackList.track)
			{
				if (!(Program.settings.exactmatch && (
					track.artist.name != artistname ||
					track.title != trackname)))
				{
					foreach (release release in track.ReleaseList.release)
						ranked.Add(new MusicBrainz.RankedTrack(track, release, artistname, trackname));
				}
			}

			ranked.Sort();
			return ranked;
		}
	}

	/// <summary>The container element for the track list.</summary>
	public class tracklist
	{
		/// <summary>The list of tracks.</summary>
		[XmlElement]
		public List<track> track;
	}

	/// <summary>A MusicBrainz track.</summary>
	public class track
	{
		/// <summary>The track ID.</summary>
		[XmlAttribute]
		public string id;
		/// <summary>The track's relevance score.</summary>
		[XmlAttribute(Namespace = "http://musicbrainz.org/ns/ext-1.0#", AttributeName = "score")]
		public int score;
		/// <summary>The track title.</summary>
		public string title;
		/// <summary>The track artist.</summary>
		public artist artist;

		/// <summary>A container element for the list of albums in which this track appears.</summary>
		[XmlElement("release-list")]
		public releaselist ReleaseList { get; set; }
	}

	/// <summary>A MusicBrainz artist.</summary>
	public class artist
	{
		/// <summary>The artist name.</summary>
		public string name;
	}

	/// <summary>A container for a list of albums.</summary>
	public class releaselist
	{
		/// <summary>The list of albums.</summary>
		[XmlElement]
		public List<release> release { get; set; }
	}

	/// <summary>A MusicBrainz album ("release").</summary>
	public class release
	{
		/// <summary>The album type. Usually "Album" yields the best results.</summary>
		[XmlAttribute]
		public string type;
		/// <summary>The album's ID.</summary>
		[XmlAttribute]
		public string id;
	}
}
